﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SPMS.Common;
using SPMS.Data;
using SPMS.Web.Mvc;

namespace SPMS.Web.Controllers
{
    /// <summary>
    /// 角色控制器。
    /// </summary>
    [AuthorizeEx]
    public class RoleController : Controller
    {
        /// <summary>
        /// 角色管理动作。
        /// </summary>
        /// <returns>
        /// 动作结果。
        /// </returns>
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 获得角色信息列表。
        /// </summary>
        /// <param name="queryModel">查询模型对象。</param>
        /// <returns>账户信息列表。</returns>
        [HttpGet]
        [AllowAnonymous]
        public JsonResult List(JsonPagingQueryModel queryModel)
        {
            //创建上下文
            using (AccountFileManagementEntities context = new AccountFileManagementEntities())
            {
                //用于保存总记录数
                int totalRecord = 0;

                //查询数据
                var query = from item in context.Roles.QueryData<Role>(queryModel, out totalRecord)
                            select new
                            {
                                item.Role_ID,
                                item.Role_Name,
                                item.Role_Title,
                                item.Role_Desc,
                                IsAssigned = false
                            };

                //获得数据
                var data = query.ToArray();

                //返回数据
                return this.JsonEx(true, data, totalRecord);
            }
        }
    }
}
